Component({
  properties: {
    title: {
      type: String,
      value: '巧巧点餐'
    },
    showBack: {
      type: Boolean,
      value: false
    },
    fixed: {
      type: Boolean,
      value: true
    },
    bgColor: {
      type: String,
      value: '#ffffff'
    }
  },
  data: {
    statusBarHeight: 0,
    navBarHeight: 0
  },
  lifetimes: {
    attached() {
      const systemInfo = wx.getSystemInfoSync();
      // 状态栏高度
      const statusBarHeight = systemInfo.statusBarHeight;
      // 导航栏高度
      const navBarHeight = (systemInfo.platform === 'ios' ? 44 : 48);
      
      this.setData({
        statusBarHeight,
        navBarHeight
      });
    }
  },
  methods: {
    navBack() {
      console.log('返回按钮被点击');
      try {
        const pages = getCurrentPages();
        console.log('当前页面栈:', pages.length);
        
        if (pages.length > 1) {
          wx.navigateBack({
            delta: 1,
            fail: (err) => {
              console.error('返回失败', err);
              wx.switchTab({
                url: '/pages/index/index'
              });
            }
          });
        } else {
          wx.switchTab({
            url: '/pages/index/index'
          });
        }
      } catch (error) {
        console.error('返回错误', error);
        wx.switchTab({
          url: '/pages/index/index'
        });
      }
    }
  }
}) 